﻿
Public Module consoleApplication2

    Public errorhandleflushTimer3Index As Guid = Nothing

    Private Sub adderrorhandleflushcall()
        If Not errorHandle.fileStream Is Nothing Then
            errorhandleflushTimer3Index = timer3.addcall(AddressOf errorHandle.flush, 30000)
            assert(errorhandleflushTimer3Index <> Guid.Empty, "cannot add errorhandle flush call to timer3.")
        End If
    End Sub

    Public Sub startmain(Optional ByVal unhandledExceptHandler As UnhandledExceptionDelegate = Nothing _
                         , Optional ByVal logfile As String = Nothing)
        startmainBase(unhandledExceptHandler, logfile)
        adderrorhandleflushcall()
    End Sub

    Public Sub finishmain()
        If errorhandleflushTimer3Index <> Nothing AndAlso errorhandleflushTimer3Index <> Guid.Empty Then
            assert(timer3.removecall(errorhandleflushTimer3Index), "cannot remove timer3 call for errorhandle.")
            errorhandleflushTimer3Index = Guid.Empty
        ElseIf Not errorHandle.fileStream Is Nothing Then
            raiseError(errorHandle.errorType.warning, "finishmain called for twice.")
        End If
        timer3.stop()
        finishmainBase()
    End Sub

End Module
